Ext.ns('event');

event.view_event = function(status,id){
	var edit;
	Ext.Ajax.request({
		url:  'services/event.php',
		method: 'POST',
		params: {act : status},
		success: function ( result, request ) {	
			var data = result.responseText.trim();
			if (data != "") {
				arr = data.split('}#');
				for (var i = 0; i < arr.length; i++) {
					arr[i] = arr[i].replace('{', '');
					arr[i] = arr[i].replace('}', '');
					arr[i] = arr[i].split('#');
				}
				var viewtable = "	<table class ='view-table' border=1px solid #CCC style='text-align:center;'>" +
				"<th>STT</th><th>Ngày</th><th>Buổi</th><th>Tên&nbsp;Sự&nbsp;Kiện</th><th>Logo</th><th>Nội&nbsp;Dung</th><th>Sửa</th><th>Chọn</th>";
				for (var i = 0; i < arr.length; i++) {
					viewtable += "<tr>";
					viewtable += "<td>" + (i + 1) + "</td>";
					viewtable += "<td>" + arr[i][1] + "</td>";
					if (arr[i][2]==0){
						viewtable += "<td>Sáng</td>";
					}
					if (arr[i][2]==1){
						viewtable += "<td>Trưa</td>";
					}
					if (arr[i][2]==2){
						viewtable += "<td>Chiều</td>";
					}
					if (arr[i][2]==3){
						viewtable += "<td>Tối</td>";
					}
					viewtable += "<td style='text-align:center;'>" + arr[i][3] + "</td>";
					viewtable+= "<td><img src='../"+ arr[i][4] +"' height='50' width='50' /></td>";
					viewtable += "<td style='text-align:justify;'>" + arr[i][5] + "</td>";
					viewtable += "<td><a href='?act=edit_event&id=" + arr[i][0] + "'><img value='" + arr[i][0] + "'  src='../images/edit.gif' border='0' title=''></a></td>";
					viewtable += "<td><input type='checkbox' id='"+status+"' name='"+status+"' value='" + arr[i][0] + "'/></td>";
					viewtable += "</tr>";
				}
				viewtable += "</table>";
				$('#'+id).html(viewtable);
			}else{
				var viewtable =  "<p style='color: Blue;line-height:15px; top:16px; font-size:20px; font-family:tahoma; text-align:center;'>" + 
				"Không tồn tại dữ liệu</p>";
				$('#'+id).html(viewtable);
			}
		},
		failure: function ( result, request ) {
    	}
	});
}
event.delete_event = function(ids,status,id_content){
	
	Ext.Ajax.request({
		url:  'services/event.php',
		method: 'POST',
		params: {	act : 'delete_event',
					ids : ids},
		success: function ( result, request ) {	
			if (result.responseText == 1){
				alert("Xóa thành công");
				event.view_event(status,id_content);
			}
		},
		failure: function ( result, request ) {
		}
	});
}
